$(function() {
     var errorMsgContainer = $("div[id*=errorMessageContainer]");
     var errorMsg = $("span[id*=errorMessage]");
     var $inputDueDate = $("#inputDueDate");
     var $inputjqxDueDate = $("#inputjqxDueDate");
     var $classWorkTypeId = $("input[id*=inputClassWorkTypeId]").val();
     var $classWorkTypes = $.parseJSON($("input[id*=classWorkTypes]").val());
     var $dropdownClassWorkTypes = $("select[id*=inputClassWorkType]");
     $("button[id*=submitClassWork]").click(copyDueDateToHiddenField);

     initializeControls();
     
     function initializeControls() {
         // Set error message
         if (errorMsg.text()) errorMsgContainer.show();
         
         // Create a jqxDateTimeInput
         $inputjqxDueDate.jqxDateTimeInput({ width: '300px', height: '25px', theme: 'base', formatString: 'MM/dd/yyyy h:mm:ss' });
         
         $.each($classWorkTypes, function (index, classWorkType) {
             var newOption = $('<option>');
             newOption.attr('value',classWorkType.classWorkTypeId).text(classWorkType.classWorkTypeName);
             $dropdownClassWorkTypes.append(newOption);
         });
         
         if ($classWorkTypeId) $dropdownClassWorkTypes.val($classWorkTypeId);
         
         if ($inputDueDate.val()) $inputjqxDueDate.jqxDateTimeInput('val', $inputDueDate.val());
     }
     
     function copyDueDateToHiddenField() {
         $inputDueDate.val($inputjqxDueDate.jqxDateTimeInput('getText'));
     }
 });